package com.cskaoyan.controller.wx.cart;

import com.cskaoyan.bean.bo.wx.cart.CartAddBO;
import com.cskaoyan.bean.bo.wx.cart.CheckBO;
import com.cskaoyan.bean.bo.wx.cart.CheckedBO;
import com.cskaoyan.bean.bo.wx.cart.UpdateCartBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO;
import com.cskaoyan.bean.vo.wx.cart.CartDeleteVO;
import com.cskaoyan.bean.vo.wx.cart.CartVO;
import com.cskaoyan.bean.vo.wx.cart.CheckOutVO;
import com.cskaoyan.service.wx.cart.WxCartService;
import org.aspectj.apache.bcel.generic.RET;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/*
 * @Auther:王贲
 * @Date:2022/9/9
 * @Description:
 * @VERSON:1.8
 */
@RestController
@RequestMapping("wx/cart")
public class WxCartController {

    @Autowired
    WxCartService wxCartService;

    @PostMapping("add")
    public BaseRespVo addCart(@RequestBody CartAddBO cartAddBO) {
        int total = wxCartService.addCartNum(cartAddBO);
        return BaseRespVo.ok(total);
    }

    @GetMapping("goodscount")
    public BaseRespVo goodsCount() {
        Integer total = wxCartService.goodsCountCartInfo();
        return BaseRespVo.ok(total);
    }

    @GetMapping("index")
    public BaseRespVo indexCart() {
        CartVO cartVO = wxCartService.selectCartInfo();
        return BaseRespVo.ok(cartVO);
    }

    @PostMapping("delete")
    public BaseRespVo deleteCart(@RequestBody CartDeleteVO cartDeleteVO) {
        Integer[] productIds = cartDeleteVO.getProductIds();
        CartVO cartVO = wxCartService.deleteCartInfo(productIds);
        return BaseRespVo.ok(cartVO);
    }

    @GetMapping("checkout")
    public BaseRespVo checkOut(CheckBO checkBO) {
        CheckOutVO checkOutVO = wxCartService.checkOutMothed(checkBO);
        return BaseRespVo.ok(checkOutVO);
    }

    @PostMapping("update")
    public AdminAdDeleteVO updateCart(@RequestBody UpdateCartBO updateCartBO) {
        wxCartService.updateCartInfo(updateCartBO);
        return AdminAdDeleteVO.ok("成功");
    }

    @PostMapping("checked")
    public BaseRespVo checkedCart(@RequestBody CheckedBO checkedBO) {
        CartVO cartVO = wxCartService.checkedCartInfo(checkedBO);
        return BaseRespVo.ok(cartVO);
    }

    @PostMapping("fastadd")
    public BaseRespVo fastaddCart(@RequestBody CartAddBO cartAddBO) {
        int total = wxCartService.fastAddCartInfo(cartAddBO);
        return BaseRespVo.ok(total);
    }
}
